#include <iostream>
#include <vector>
using namespace std;
class Printer {
public:
    vector<int> clockwisePrint(vector<vector<int> > mat, int n, int m) {
        // write code here
        vector<int> ans;
        int left = 0, right = n - 1, top = 0, down = m - 1;
        while (true) {
            for (int i = left; i <= right; i++)
                ans.push_back(mat[top][i]);
            if (++top > down) break;
            for (int i = top; i <= down; i++)
                ans.push_back(mat[i][right]);
            if (--right < left) break;
            for (int i = right; i >= left; i--)
                ans.push_back(mat[down][i]);
            if (--down < top) break;
            for (int i = down; i >= top; i--)
                ans.push_back(mat[i][left]);
            if (++left > right) break;
        }
        return ans;
    }
};
int main()
{
    vector<vector<int>> mat = { {1, 2, 3}, {4, 5, 6}, {7, 8, 9} };
    vector<int> retnums = Printer().clockwisePrint(mat, mat.size(), mat[0].size());
    for (const auto& num : retnums)
        cout << num << " ";
    return 0;
}